﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnvDTE;
using VsxFactory.Modeling.VisualStudio;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using System.ComponentModel;
using VsxFactory.Modeling.Strategies;

namespace VsxFactory.Modeling.StrategyManager.Strategies
{
    [ComVisible(true)]
    public abstract class BaseStrategyExtender : IStrategyExtender
    {
        private IExtenderSite extenderSite;
        private int cookie;
        [Browsable(false)]
        public IVsProjectFileItem Item { get; private set; }
        [Browsable(false)]
        public IServiceProvider ServiceProvider { get; private set; }

        internal BaseStrategyExtender(IServiceProvider serviceProvider, IVsProjectFileItem item)
        {
            Contract.Requires(item != null);
            Contract.Requires(serviceProvider != null);

            this.ServiceProvider = serviceProvider;
            this.Item = item;
        }

        void IStrategyExtender.Init(IExtenderSite extenderSite, int cookie)
        {
            this.cookie = cookie;
            this.extenderSite = extenderSite;
        }

        ~BaseStrategyExtender()
        {
            try
            {
                if (extenderSite != null && cookie != 0)
                    extenderSite.NotifyDelete(cookie);
            }
            catch { }
        }
    }
}
